package com.design.structure.flyweight.cainiao;

import java.util.HashMap;

/**
 * @ProjectName: design
 * @Package: com.design.structure.flyweight.cainiao
 * @ClassName: ShapeFactory
 * @Author: shenaiguo
 * @Description: 工厂类
 * @Date: 2020/9/18 0018 18:37
 */
// 步骤3
public class ShapeFactory {
    private static final HashMap<String, Shape> circleMap = new HashMap<>();

    public static Shape getCircle(String color) {
        Circle circle = (Circle)circleMap.get(color);

        if(circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        }
        return circle;
    }
}
